<template>
	<view>
		<uni-nav-bar :fixed="true" title="管理" :border="false" @clickLeft="$pageBack()" left-icon="back" background-color="#ECE6D5" :status-bar="true"></uni-nav-bar>
		<view class="block">
			<view class="its flex_jc_sb">
				<view class="t1">分社管理权转让</view>
				<view class="">
					<switch :checked="istrue" @change="switchChange1" style="transform: scale(0.8)" color="#D8C6A7" />
				</view>
			</view>
			<view class="its flex_jc_sb">
				<view class="t1">稻使</view>
				<view class="">
					<switch :checked="isVipType" @change="switchChange" style="transform: scale(0.8)" color="#D8C6A7" />
				</view>
			</view>
		</view>
		<uni-popup ref="popupT1" type="center">
			<view class="globalPopup">
				<uni-icons @click="close" type="closeempty" size="20" class="close" color="#AEAEAE"></uni-icons>
				<view class="title">提示</view>
				<view class="content">确定“{{ usetData.name }}”为新社长 你将自动放弃社长身份？</view>
				<view class="btns flex_jc_sb">
					<view class="bt b1" @click="close">取消</view>
					<view class="bt b2" @click="confirmTransfer">确认</view>
				</view>
			</view>
		</uni-popup>
		<uni-popup ref="popupT2" type="center">
			<view class="globalPopup">
				<uni-icons @click="close" type="closeempty" size="20" class="close" color="#AEAEAE"></uni-icons>
				<view class="title">提示</view>
				<view class="content">{{isVipType?'增加':'取消'}}  “{{ usetData.name }}”稻使权限？</view>
				<view class="btns flex_jc_sb">
					<view class="bt b1" @click="close">取消</view>
					<view class="bt b2" @click="confirmVipType">确认</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script setup>
import { ref, reactive, getCurrentInstance } from 'vue';
import { onLoad, onShow, onReachBottom, onPageScroll } from '@dcloudio/uni-app';
import { changeVip, transferGroup } from '@/api/branch/member.js';
import { toast, showConfirm } from '@/utils/common.js';
const popupT1 = ref(null);
const popupT2 = ref(null);
const close = () => {
	istrue.value = false;
	console.log(istrue.value);
	popupT1.value.close();
	popupT2.value.close();
};
const isVipType = ref(false);
const switchChange = (e) => {
	isVipType.value = e.detail.value;
	popupT2.value.open();
};
const confirmVipType = ()=>{
	changeVip({userId:usetData.id}).then(res=>{
		if(res.code == 200){
			toast('已设置稻使身份')
			close()
			uni.$emit('changeGetList')
		}
	})
}
const istrue = ref(false);
const switchChange1 = (e) => {
	istrue.value = e.detail.value;
	popupT1.value.open();
};
const confirmTransfer = () => {
	transferGroup({userId:usetData.id}).then(res=>{
		if(res.code == 200){
			toast('会长转让成功')
			setTimeout(()=>{
				uni.switchTab({
					url:'/pages/user/user'
				})
				uni.$emit('isManagement')
				uni.removeStorageSync('management')
			},500)
		}
	})
};
const usetData = reactive({});
onLoad(() => {
	Object.assign(usetData, uni.getStorageSync('management'));
	if(usetData.vipType == 2){
		isVipType.value = true
	}else{
		isVipType.value = false
	}
});
</script>
<style lang="scss">
page {
	background: #f7f8f6;
}
.block {
	width: 710rpx;
	background: #ffffff;
	border-radius: 20rpx 20rpx 20rpx 20rpx;
	margin: 20rpx auto;
	padding: 20rpx;
	box-sizing: border-box;
	.its {
		padding-bottom: 20rpx;
		margin: 0rpx auto 20rpx;
		border-bottom: 1px solid #e5ded1;
		.t1 {
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 24rpx;
			color: #1b1b1b;
		}
	}
	.its:last-child {
		padding: 0rpx;
		border: none;
		margin: 0rpx;
	}
}
</style>
